/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: fzykd
 * Date: 2023-03-05
 * Time: 19:57
 */

public class HashSetStructure {
    public static void main(String[] args) {
        //模拟一个HashSet的底层 (其实就是HashMap 的底层结构)
        //这样是底层结构 存储效率是很高的

        //1.创建一个数组 数组类型是Node[]
        Node[] table = new Node[16];
        System.out.println("table=" + table);
        //2.创建节点
        Node john = new Node("john",null);
        //把john这个节点放到 数组是2的位置上
        table[2] = john;
        Node jack = new Node("jack",null);
        //将Jack 节点挂载到john
        john.next = jack;

        Node rose = new Node("Rose",null);
        jack.next = rose; //将rose挂载到jack后面
        System.out.println("table=" + table);

        Node luck = new Node("luck", null);
        table[3] = luck; //把luck方到table表的第三个位置来
        System.out.println("table=" + table);

    }
}


class Node{ //节点 存储数据 指向下一个节点 形成链表
    Object item; //存放数据
    Node next; //指向下一个节点

    public Node(Object item, Node next) {
        this.item = item;
        this.next = next;
    }

    @Override
    public String toString() {
        return "Node{" +
                "item=" + item +
                ", next=" + next +
                '}';
    }
}